const titbit = require('titbit');
const pg = require('pg');
const {request} = require('https');
const token = require('titbit-token');
const tbloader = require('titbit-loader');
const dbcfg = require('./dbconfig');
const endadminlogin = require('./controller/endadminlogin');
process.chdir(__dirname);
let cert_path = '/usr/local/share';
const app = new titbit({
    debug: true,
    globalLog:true,
    cert: `${cert_path}/api.124ss.xyz.pem`,
    key: `${cert_path}/api.124ss.xyz.key`
})

let psql=new pg.Pool(dbcfg);

let tb = new tbloader({
    usersFile: 'endusers.js',
    loginFile: 'endadminlogin.js',
    postsFile: 'endcontent.js',
    wearFile: 'endwear.js',
    eatFile: 'endeat.js',
    playFile: 'endplay.js'
});
tb.init(app);

app.addService('psql',psql);
app.addService('imagePath', `/usr/images`);


let tok = new token({
    expires: 7200,
    key: '1qaz2wqx32dc4rf750gb6yhn7ujmki89',
    iv: '1q2r3e41536y7u8i'
})

app.addService('tok', tok);

let usertok = new token({
    expires: 7200,
    key: '1qaz2wqx32dc4rf750gb6yhn7uj1ki67',
    iv: '1q2r3e41536y124i'
})

app.addService('usertok', usertok);

app.options('/', async c => {}, {group: '/'});

app.run(2355);

